﻿using System;
using System.Web.Security;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace MobileManager.Mini
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
        }

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            btnLogin.Click += new System.Web.UI.ImageClickEventHandler(this.btnLogin_Click);
        }

        private void btnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            string strUserID = txtUsername.Value.Trim(), strPWD = txtPass.Value.Trim();
            if (string.IsNullOrEmpty(strUserID))
            {
                lblMsg.Text = "用户名不能为空!";
                return;
            }
            if (string.IsNullOrEmpty(strPWD))
            {
                lblMsg.Text = "密码不能为空!";
                return;
            }
            if (!strUserID.Equals("cwyang"))
            {
                return;
            }
            if (MM.DAL.T_Users.CheckExist(strUserID, MM.Common.DESEncrypt.Encrypt(strPWD)))
            {
                MM.DAL.T_Users userDAL = new MM.DAL.T_Users();
                MM.Model.T_Users useModel = userDAL.GetCurUser(strUserID);
                Session["CurUser"] = useModel;
                MM.DBUtility.BLSqlData.InsertLogs(strUserID, "登录了系统", "系统登录");
                Response.Redirect("MonitorIndex.aspx");
            }
            else
            {
                lblMsg.Text = "用户名或密码错误!";
            }
        }
    }
}
